<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/404', 'ErrorController@__404')->name('404');
Route::get('/503', 'ErrorController@__503')->name('503');

Route::get('/register', 'AuthController@register')->name('register');
Route::get('/registersuccess', 'AuthController@registerSuccess')->name('registerSuccess');
Route::get('/autologin', 'AuthController@autoLogin')->name('autoLogin');
Route::get('/auth/smsverify', 'AuthController@smsVerify')->name('smsVerify');
Route::get('/logout', 'AuthController@logout');
Route::get('/weixin/getweixinuser', 'WeixinController@getWeixinUser')->name('getWeixinUser');
Route::get('/weixin/getweixinuserinfo', 'WeixinController@getWeixinUserinfo')->name('getWeixinUserinfo');

Route::get('/callback', 'CallbackController');
Route::any('/callback/weixinqy', 'CallbackController@weixinQy');
Route::post('/callback/wxpay', 'CallbackController@wxPay');

/**
 * 普通请求，需要检验微信权限
 */
Route::group(['middleware'=>['weixin.auth']], function(){

    Route::get('/', 'IndexController@index')->name('/');

    Route::get('/order', 'OrderController@index');
    Route::get('/order/offeringlist', 'OrderController@offeringList');
    Route::get('/order/offer/{order}', 'OrderController@offer');
    Route::get('/order/offered/{order}', 'OrderController@offered');
    Route::any('/order/offerStart/{order}', 'OrderController@offerStart');
    Route::get('/order/listmasteroffered', 'OrderController@listMasterOffered');
    Route::get('/order/listMasterServing', 'OrderController@listMasterServing');
    Route::get('/order/listMasterFinished', 'OrderController@listMasterFinished');
    Route::get('/order/listMasterAll', 'OrderController@listMasterAll');
    Route::get('/order/detail/{order}', 'OrderController@detail');
    Route::get('/order/appoint/{order}', 'OrderController@appoint');
    Route::any('/order/delivery/{order}', 'OrderController@delivery');
    Route::get('/order/finish/{order}', 'OrderController@finish');
    Route::post('/order/applyfinish', 'OrderController@applyFinish');
    Route::get('/order/refund/{order}', 'OrderController@refund');
    Route::get('/order/except/{order}', 'OrderController@except');
    Route::get('/order/replenishlist/{order}', 'OrderController@replenishList');

    Route::get('/message', 'MessageController@index');
    Route::get('/message/listsystem', 'MessageController@listSystem');
    Route::get('/message/listorder', 'MessageController@listOrder');
    Route::get('/message/read/{notification}', 'MessageController@read');

    Route::get('/master', 'MasterController@index');
    Route::get('/master/detail', 'MasterController@detail');
    Route::get('/master/detail/changephone', 'MasterController@changePhone');
    Route::any('/master/detail/backupphone', 'MasterController@backupPhone');
    Route::any('/master/detail/changearea', 'MasterController@changeArea');
    Route::any('/master/detail/changeservicetype', 'MasterController@changeServiceType');
    Route::any('/master/detail/changeserviceareas', 'MasterController@changeServiceAreas');
    Route::any('/master/detail/changeserviceperiod', 'MasterController@changeServicePeriod');
    Route::any('/master/detail/changeserviceextra', 'MasterController@changeServiceExtra');
    Route::any('/master/detail/changejobtype', 'MasterController@changeJobType');

    Route::get('/master/evaluate', 'MasterController@evaluateWaiting');//评价
    Route::get('/master/evaluate/all', 'MasterController@evaluateAll');

    Route::get('/master/complain', 'MasterController@complain');//投诉
    Route::get('/master/complain/waiting', 'MasterController@complainWaiting');
    Route::get('/master/complain/handled', 'MasterController@complainHandled');
    Route::get('/master/complain/detail/{complain}', 'MasterController@complainDetail');

    Route::get('/refund', 'RefundController@index');//退款
    Route::any('/refund/detail/{refund}', 'RefundController@detail');
    Route::get('/refund/arbitrate/{refund}', 'RefundController@arbitrate');

    Route::get('/wallet', 'WalletController@index');//钱包
    Route::any('/wallet/password', 'WalletController@password');//修改钱包密码
    Route::get('/wallet/assurefund', 'WalletController@assureFund');//保证金
    Route::get('/wallet/assurefundhistory', 'WalletController@assureFundHistory');
    Route::any('/wallet/returnassurefund', 'WalletController@returnAssureFund');//退还保证金
    Route::get('/wallet/bill', 'WalletController@bill');//账单
    Route::get('/wallet/billdetail/{start_time}', 'WalletController@billDetail');//账单
    Route::get('/wallet/cash', 'WalletController@cash');//提现
    Route::any('/wallet/accountbind', 'WalletController@accountBind')->name('accountBind');//提现账号绑定
    Route::any('/wallet/cashstart', 'WalletController@cashStart');//发起提现
    Route::get('/wallet/history', 'WalletController@history');//钱包明细记录

    Route::post('/pay/form', 'PayController@form');
    Route::post('/paytest/form', 'PayController@form');
});

/**
 * ajax请求
 */
Route::group(['namespace'=>'Ajax','prefix' => 'ajax'], function(){

    Route::post('/auth/smsverify', 'AuthController@smsVerify');
    Route::post('/register', 'AuthController@register');

    Route::post('/order/appoint', 'OrderController@appoint');
    Route::post('/order/mark', 'OrderController@mark');
    Route::post('/order/reply', 'OrderController@reply');
    Route::post('/order/listmasterall', 'OrderController@listMasterAll');
    Route::post('/order/listmasteroffered', 'OrderController@listMasterOffered');

    Route::post('/master/changephone', 'MasterController@changePhone');
    Route::post('/master/changheadimg', 'MasterController@changHeadimg');
    Route::post('/master/updatedetail', 'MasterController@updateDetail');

    Route::post('/wallet/applycash', 'WalletController@applyCash');

    Route::post('/validate/phoneexists', 'ValidateController@phoneExists');
    Route::post('/validate/checkconfirmcode', 'ValidateController@checkConfirmCode');
    Route::post('/validate/checkwalletpassword', 'ValidateController@checkWalletPassword');

    Route::post('/pay/checkpaymentsuccess', 'PayController@checkPaymentSuccess');
    Route::post('/pay/balancepay', 'PayController@balancePay');
});

/**
 * 静态资源请求
 */
Route::group([], function(){

    Route::get('/css/{path}', function($path){
        try{
            return response()->file(public_path('css'.DIRECTORY_SEPARATOR.$path),['Content-Type'=>'text/css']);
        }catch(Exception $e){
            return 'file miss';
        }
    })->where('path', '[\w\.\/-]+');

    Route::get('/js/{path}', function($path){
        try{
            return response()->file(public_path('js'.DIRECTORY_SEPARATOR.$path),['Content-Type'=>'application/x-javascript']);
        }catch(Exception $e){
            return 'file miss';
        }
    })->where('path', '[\w\.\/-]+');

    Route::get('/images/{path}', function($path){
        $file = public_path('images'.DIRECTORY_SEPARATOR.$path);
        return is_file($file) ? response()->file($file,['Content-Type'=>File::mimeType($file)]) : 'file miss';
    })->where('path', '[\w\.\/-]+');

    Route::get('/upload/{path}', 'UploadController@get')->where('path', '.+')->name('uploaded');

});

Route::any('/test', 'TestController@index');